#include "StdAfx.h"
#include "FFEncodeFilter.h"
#include "FFEncodeInputPin.h"



CFFEncodeFilter::CFFEncodeFilter(LPUNKNOWN lpunk, HRESULT* phr)
: CBaseFilter(FDE_FILTER_NAME, lpunk, this, CLSID_FDEMuxFilter, phr)
{
	m_pInputAudioPin = new CFFEncodeInputPin(this, this, phr, L"Video In");
	m_pInputVideoPin = new CFFEncodeInputPin(this, this, phr, L"Audio In");
}

CFFEncodeFilter::~CFFEncodeFilter(void)
{
	delete m_pInputVideoPin;
	delete m_pInputAudioPin;
}

CUnknown * WINAPI CFFEncodeFilter::CreateInstance(LPUNKNOWN punk, HRESULT *phr)
{
	ASSERT(phr);

	CFFEncodeFilter *pNewObject = new CFFEncodeFilter(punk, phr);
	if (pNewObject == NULL) {
		if (phr)
			*phr = E_OUTOFMEMORY;
	}

	return pNewObject;

}


STDMETHODIMP CFFEncodeFilter::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
	if( riid == IID_IFileSinkFilter){
		//m_cRef++;
		//return GetInterface((IFileSinkFilter *)this, ppv);
		*ppv = (IFileSinkFilter*)&filssink;
		return S_OK;
	}else{
		return CBaseFilter::NonDelegatingQueryInterface(riid, ppv);
	}
}


int CFFEncodeFilter::GetPinCount()
{
	return 2;
}

CBasePin* CFFEncodeFilter::GetPin(int n)
{
	if(n == 1)return m_pInputAudioPin;
	else if(n == 0) return m_pInputVideoPin;
	return NULL;

}


STDMETHODIMP CFFEncodeFilter::Run(REFERENCE_TIME tStart)
{
	CAutoLock cLock(this);

	return CBaseFilter::Run(tStart);
}

STDMETHODIMP CFFEncodeFilter::Pause()
{
	CAutoLock cLock(this);

	FILTER_STATE fs = m_State;

	HRESULT hr = __super::Pause();
	if(FAILED(hr)) return hr;

	return hr;
}

STDMETHODIMP CFFEncodeFilter::Stop()
{	
	CAutoLock cLock(this);
	HRESULT hr = __super::Stop();
	if( FAILED(hr) ) return hr;
	return hr;
}




